#ifndef _VIDEO_H
#define _VIDEO_H

#include <QWidget>
#include <opencv2/opencv.hpp>
using namespace cv;

class QTimer;
class QPaintEvent;
class QResizeEvent;
class QMouseEvent;
class QImage;
class QRect;
class QPixmap;

class DocWidget: public QWidget
{
	Q_OBJECT
public:
	  DocWidget(QWidget *parent = 0);
	~DocWidget();

signals:
  void drawHist(int* red, int* green, int* blue);

public slots:
  void update();
  void start();
  void stop();
  void setFilter(int mode);
  void setFactor(double fac);
  void snap();

protected:
	void paintEvent(QPaintEvent *event);
	void resizeEvent(QResizeEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
	void fitImage();
	void filterImage();
	void roiHist(Mat image);

	enum {MouseNone, TopLeft, TopRight, BottomLeft, BottomRight} mouseMode;
    QTimer *timer;
    VideoCapture *cap;
    double m_fps;
	QImage *m_pixmap;
	int imageWidth, imageHeight;
	int m_imageWidth, m_imageHeight;
	Mat m_frame, m_image,m_oframe;
	QRect roiRect;

	int m_filterMode;
	double m_fac;

	int dstx,dsty,srcx,srcy,srcw,srch;
	int roix,roiy,roiw,roih;
};

#endif
